home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DllSys_Files / ERRCRIT / L2c.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  1.4 KB  |  45 lines

  1. // Dynamic link library implementation of NeuroSolutions L2Criterion component 
  2.  
  3. #include "NSDLL.h" 
  4.  
  5. /***********************************/
  6. /* Forward activation of component */
  7.  
  8. __declspec(dllexport) NSFloat performCriterion(
  9.     DLLData    *instance,        // Pointer to instance data (may be NULL)
  10.     NSFloat *costDerivative,     // Pointer to the cost derivative vector, i.e. output sensitivity
  11.     int     rows,            // Number of rows of PEs in the layer
  12.     int     cols,            // Number of columns of PEs in the layer
  13.     NSFloat *output,         // Pointer to the output layer of the network
  14.     NSFloat *desired,        // Pointer to the desired output vector, same length as output layer
  15.     BOOL    testing            // Flag to indicate whether or not the data is for the test set
  16.     )
  17. {
  18.     int i,length=rows*cols;
  19.     NSFloat cost=0.0f;
  20.  
  21.     for (i=0; i<length; i++) {
  22.         costDerivative[i] = desired[i] - output[i];
  23.         cost += 0.5f*costDerivative[i]*costDerivative[i];
  24.     }
  25.     return cost;
  26. }
  27.  
  28. /******************************************/
  29. /* Management of instance data (OPTIONAL) */
  30. /*
  31. __declspec(dllexport) DLLData *allocCriterion(
  32.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  33.     int     rows,        // Number of rows of PEs in the layer
  34.     int     cols        // Number of columns of PEs in the layer
  35.     )
  36. {
  37.     DLLData *instance = allocDLLInstance(oldInstance);
  38.     return instance;
  39. }
  40.  
  41. __declspec(dllexport) void freeCriterion(DLLData *instance)
  42. {
  43.     freeDLLInstance(instance);
  44. }
  45. */